<?php

namespace App\Http\Controllers;

use app\Serve\Token;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
     * 登录处理
     */
    public function dologin(){
        try {
            $user=\request()->post();
//        dd(bcrypt($user['password']));
            $res=Auth::attempt(['username'=>$user['username'],'password'=>$user['password']]);
            if ($res){
                return redirect('index');
            }else{
                return redirect('login')->withErrors('登录失败！');
            }
        }catch (Exception $exception){
            dd($exception->getMessage());
        }
    }

    /**
     * 退出
     */
    public function logout(){
        try {
            Auth::logout();
            return redirect('login');
        }catch (Exception $exception){
            dd($exception->getMessage());
        }
    }
}
